import requests
from apiAutomation import app
from apiAutomation.api.login import LoginApi

class ApkApi:
    def __init__(self, token):
        self.add_apk_url = app.BATH_URL + "/apk/addApk"
        # 请求头
        self.headers_dict_json = {
            "content-type": "applocation/json",
            "token": token
        }
        self.headers_dict_form = {
            "token": token
        }

    def add_apk(self, version):
        # 请求数据类型
        data = {
            "is_belong": 1,
            "version": version
        }
        # 上传的文件'file': open('D:/test.apk',
        # files = {'file':  open(r'E:\测试工作\换电柜\v0.6测试\app-release.apk', 'rb')}
        files = {'file': ("app-release.apk", open(r'E:\测试工作\换电柜\v0.6测试\app-release.apk', 'rb'),
                          'application/vnd.android.package-archive')}
        return requests.post(url=self.add_apk_url, headers=self.headers_dict_form, data=data, files=files)


if __name__ == '__main__':
    token = LoginApi().get_token()
    print(token)
    print(ApkApi(token).add_apk("11.0101").json())
